package com.wujie.section02;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by wujieliu on 2017/10/13.
 */
public class SwingObserverExample {
    JFrame jFrame;

    public static void main(String[] args) {
        SwingObserverExample example = new SwingObserverExample();
        example.go();
    }
    public void go() {
        jFrame = new JFrame();
        jFrame.setSize(600,400);//设置窗体大小

        jFrame.setBackground(Color.WHITE);//设置窗体的背景颜色

        jFrame.setLocation(1000,600);//设置窗体的显示位置

        jFrame.setVisible(true);//让组建显示
        JButton button = new JButton("Should I do it?");
        button.addActionListener(new AngelListener());
        button.addActionListener(new DevilListener());
        jFrame.getContentPane().add(BorderLayout.CENTER, button);
        // 在这里设置frame属性
    }
    class AngelListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Don't do it, you might regret it!");
        }
    }
    class DevilListener implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Come on, do it!");
        }
    }
}
